package com.audaque.springboot.foshanupload.web.servletdemo.controller;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//在SpringBootApplication上使用@ServletComponentScan注解后:Servlet、Filter、Listener可以直接通过@WebServlet、@WebFilter、@WebListener注解自动注册，无需其他代码
//方式1
@WebServlet(name = "scopeServlet", urlPatterns = "/servlet/scope")
public class ScopeServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setAttribute("requestScope", "李二");

        req.getSession().setAttribute("sessionScope", "李三");

        req.getServletContext().setAttribute("servletContextScope", "李四");

        //转发：所有域数据存在
        // req.getRequestDispatcher("/view/scope").forward(req, resp);
        //包含：所有域数据变为问号,中文编码问题
         req.getRequestDispatcher("/view/scope").include(req, resp);
         req.getRequestDispatcher("/view/index-jsp").include(req, resp);
        //重定向：request域为n    ull
        //resp.sendRedirect(req.getContextPath() + "/view/scope");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }

}
